package com.zhpan.indicator.drawer;

import ohos.agp.components.Component;
import ohos.agp.render.Canvas;

import com.zhpan.indicator.base.MeasureResult;
import com.zhpan.indicator.options.IndicatorOptions;

/**
 * 形状代理类
 *
 * @since 2021-04-13
 */
public class DrawerProxy implements IDrawer {
    private IndicatorOptions mOptions;
    private IDrawer mDrawer;

    /**
     * 根据配置类创建代理类
     *
     * @param options 配置
     */
    public DrawerProxy(IndicatorOptions options) {
        this.mOptions = options;
        init();
    }

    /**
     * 布局测量
     *
     * @param changed 是否改变
     * @param left 左坐标
     * @param top 上坐标
     * @param right 右坐标
     * @param bottom 下坐标
     */
    @Override
    public void onLayout(boolean changed, int left, int top, int right, int bottom) {
    }

    @Override
    public MeasureResult onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        return mDrawer.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {
        mDrawer.onDraw(component, canvas);
    }

    /**
     * 设置配置
     *
     * @param options 配置
     */
    public void setOptions(IndicatorOptions options) {
        this.mOptions = options;
        init();
    }

    private void init() {
        mDrawer = DrawerFactory.createDrawer(mOptions);
    }
}
